package cn.kgc.service;

import cn.kgc.mapper.UserMapper;
import cn.kgc.pojo.User;
import cn.kgc.util.Page;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @描述
 * @author：LY
 * @2018/11/1 19:58
 */
@Service
public class UserServiceImpl implements UserService {

    @Resource
    private UserMapper userMapper;


    @Override
    public boolean deleteByID(String id) {
        return userMapper.deleteByPrimaryKey(Long.valueOf(id))>0;
    }

    @Override
    public boolean insert(User user) {
        if(user!=null){
            return userMapper.insert(user)>0;
        }
        return false;
    }

    @Override
    public User selectByID(String id) {
        if(id!=null && id.matches("\\d*")){
            return userMapper.selectByPrimaryKey(Long.valueOf(id));
        }
        return null;
    }

    @Override
    public boolean updateByID(User user) {
        if(user!=null){
            return userMapper.updateByPrimaryKey(user)>0;
        }
        return false;
    }



    @Override
    public User loginSelect(String userCode, String userPassword) {
        if(userCode !=null && userCode !="" && userPassword !=null && userPassword !="") {
            return userMapper.loginSelect(userCode,userPassword);
        }
        return null;
    }

    @Override
    public Page<User> userInfo(User user, String pageNum) {
        int index = 1;
        if(pageNum!=null && pageNum.matches("\\d*")){
            index = Integer.valueOf(pageNum);
        }
        Page<User> page = new Page<>(userMapper.userCount(user),index);
        page.setTiaojian(user);
        List<User> list = userMapper.userInfo(page);
        page.setList(list);
        return page;
    }


    @Override
    public User ajaxName(String name) {
        return userMapper.ajaxName(name);
    }


}
